package com.biscuit.page.basicservice.conf.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import springfox.documentation.builders.*;
import springfox.documentation.service.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mazihao
 * @createTime 2024/3/7 16:54
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@EnableWebMvc
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        List<RequestParameter> globalOperationParameters = new ArrayList<>();
        globalOperationParameters.add(new RequestParameterBuilder()
                .in(ParameterType.HEADER)
                .name("Authorization")
                .description("登录授权标识")
                .required(false)
                .build());

        return new Docket(DocumentationType.OAS_30)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.biscuit.page.basicservice.remote.api"))
                .paths(PathSelectors.any())
                .build()
                .globalRequestParameters(globalOperationParameters);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .description("knife4j在线API接口文档")
                .contact(new Contact("Biscuit", "#", "biscuitv@163.com"))
                .version("v3.0.3")
                .title("knife4j在线API接口文档")
                .build();
    }

}
